package com.countryside.controller;

import com.countryside.pojo.Company;
import com.countryside.pojo.User;
import com.countryside.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;

@Controller
public class CompanyController {

    @Autowired
    CompanyService companyService;

    /**
     * 完善公司信息 添加公司
     * @param company
     * @param province
     * @param city
     * @param session
     * @return
     */
    @PostMapping("/addCompany")
    public String addCompany(Company company,
                             String province, String city,
                             HttpSession session) {
        User user = (User) session.getAttribute("user");
        company.setUserId(user.getId());
        company.setCompanyAddress(province + "/" + city);
        companyService.addCompany(company);
        return "redirect:user/getEmployeeWork";
    }

    /**
     * 修改公司信息
     * @param company
     * @param province
     * @param city
     * @return
     */
    @PostMapping("/updateCompany")
    public String updateCompany(Company company, String province, String city) {
        company.setCompanyAddress(province + "/" + city);
        companyService.updateCompany(company);
        return "redirect:user/getEmployeeWork";
    }
}
